package cn.jsj.cxsys.dao;

import java.util.*;
import cn.jsj.cxsys.pojo.*;
import org.apache.ibatis.annotations.*;
import cn.jsj.cxsys.dao.dynamicSQL.*;

public interface RecordFunction
{
    @Results(id = "toUser", value = { @Result(id = true, property = "userID", column = "user_id"), @Result(property = "teleNumber", column = "tele_number"), @Result(property = "className", column = "class_name"), @Result(property = "name", column = "name"), @Result(property = "account", column = "account"), @Result(property = "password", column = "password") })
    @Select({ "select * from vi_user where user_id in (select lader_id from tb_lab where lab_id = (select lab_id from tb_record where record_id=#{recordID})) limit 1" })
    User getTeacherOfRecordLab(final int recordID);

    @Insert({ "insert into tb_record (user_id,pc_num,lab_id,in_time) values (#{userID},#{pcNum},#{labID},#{startTime})" })
    int siginRecord(final int userID, final int pcNum, final int labID, final String startTime);

    @Update({ "update tb_record set out_time=#{overTime} , action=#{str} where user_id=#{userID} and out_time is null" })
    int sigoutRecord(final int userID, final String overTime, final String str);

    @Insert({ "insert into tb_record (user_id,lab_id,in_time) values (#{userID},#{labID},#{startTime})" })
    int siginLab(final int userID, final int labID, final String startTime);

    @Results(id = "toRecord", value = { @Result(id = true, property = "recordID", column = "record_id"), @Result(property = "inTime", column = "in_time"), @Result(property = "outTime", column = "out_time"), @Result(property = "computerNum", column = "pc_num"), @Result(property = "user.userID", column = "user_id"), @Result(property = "user.teleNumber", column = "tele_number_stu"), @Result(property = "user.name", column = "stu_name"), @Result(property = "user.className", column = "class_name"), @Result(property = "user.account", column = "account"), @Result(property = "lab.labID", column = "lab_id"), @Result(property = "lab.labNum", column = "lab_num"), @Result(property = "lab.labName", column = "lab_name"), @Result(property = "lab.laderName", column = "lader_name"), @Result(property = "lab.laderTeleNumber", column = "tele_number_lader"), @Result(property = "active", column = "action") })
    @Select({ "select * from vi_record where lab_id=#{labID}" })
    List<Record> getRecordOfLab(@Param("labID") final int labID);

    @ResultMap({ "toRecord" })
    @Select({ "select * from vi_record" })
    List<Record> findAllRecord();

    @Select({ "select count(*) from tb_record" })
    int countRecordNumber();

    @Select({ "select count(*) as value,stu_name as name from vi_record where date_sub(now(),interval 30 day) <= in_time group by account" })
    List<Singin> top10OfSingin();

    @ResultMap({ "toRecord" })
    @Select({ "select * from vi_record where date_sub(now(),interval 30 day) <= in_time" })
    List<Record> getThisMouthRecord();

    @Select({ "select lab_id from tb_record where user_id=#{userID} and out_time is null" })
    int getLabIdOfUserIn(@Param("userID") final int userID);

    @Select({ "select * from vi_record where lab_num=#{labNum} and in_time>=#{startTime} and out_time<=#{limitTime}" })
    @ResultMap({ "toRecord" })
    List<Record> getRecordToDownLoad(@Param("labNum") final String labNum, @Param("startTime") final String startTime, @Param("limitTime") final String limitTime);

    @Select({ "select * from vi_record where in_time>=#{startTime} and out_time<=#{limitTime}" })
    @ResultMap({ "toRecord" })
    List<Record> getRecordToDownLoadWithoutLab(@Param("startTime") final String startTime, @Param("limitTime") final String limitTime);

    @ResultMap({ "toRecord" })
    @SelectProvider(type = DynamicSQLFactory.class, method = "RecordsScreen")
    List<Record> findRecords(@Param("studentAccount") final String studentAccount, @Param("teacherAccount") final String teacherAccount, @Param("startTime") final String startTime, @Param("overTime") final String overTime, @Param("labID") final int labID, @Param("labNum") final String labNum, @Param("pcID") final int pcID);
}
